package com.iot.core.data.service;


import com.iot.core.data.IdNameAttrDto;
import com.iot.core.data.IdNameDto;
import com.iot.core.data.entity.HtUserRole;
import com.iot.core.data.mapper.HtUserRoleMapper;
import com.iot.core.manager.auth.HtDeptBaseDto;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.iot.core.data.entity.table.HtDeptTableDef.HT_DEPT;
import static com.iot.core.data.entity.table.HtRoleTableDef.HT_ROLE;
import static com.iot.core.data.entity.table.HtUserDeptTableDef.HT_USER_DEPT;
import static com.iot.core.data.entity.table.HtUserRoleTableDef.HT_USER_ROLE;
import static com.iot.core.data.entity.table.HtUserTableDef.HT_USER;

@Service
public class HtUserRoleServiceImpl extends  ServiceImpl<HtUserRoleMapper, HtUserRole> implements IHtUserRoleService {
    public  List<IdNameDto> getRoles(Long uid, Long did){
        var qw=QueryWrapper.create()
                .select(HT_ROLE.ID.as("id") )
                .select(HT_ROLE.NAME.as("name")  )
                .from(HT_USER_ROLE).as("a")
                .join(HT_ROLE).as("b")
                .on(HT_USER_ROLE.HTUSER_ID.eq(uid)
                        .and(HT_USER_ROLE.HTDEPT_ID.eq(did) )
                        .and( HT_USER_ROLE.HTROLE_ID.eq(HT_ROLE.ID) )
                );
        var l=getMapper().selectListByQueryAs(qw,IdNameDto.class);
        return l;
    }
    public  List<IdNameAttrDto> getRoles(List<Long> luid, Long did){
        var qw=QueryWrapper.create()
                .select(HT_ROLE.ID.as("id") )
                .select(HT_ROLE.NAME.as("name")  )
                .select(HT_USER_ROLE.HTUSER_ID.as("id1")  )
                .from(HT_USER_ROLE).as("a")
                .join(HT_ROLE).as("b")
                .on(HT_USER_ROLE.HTUSER_ID.in(luid)
                        .and(HT_USER_ROLE.HTDEPT_ID.eq(did) )
                        .and( HT_USER_ROLE.HTROLE_ID.eq(HT_ROLE.ID) )
                );
        var l=getMapper().selectListByQueryAs(qw,IdNameAttrDto.class);
        return l;
    }


}
